package com.clhbolg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @Author cailinhu
 * @Description TODO
 * @Date 2023/3/1 17:06
 * @Version 1.0
 */
@Configuration
public class MyRedisConfig {
    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        //key的序列化操作
        template.setKeySerializer(new StringRedisSerializer());
        //value的序列号操作
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //hash类型key的序列化操作
        template.setHashKeySerializer(new StringRedisSerializer());
        //hash类型value序列化的操作
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        template.setConnectionFactory(factory);
        return template;
    }

}
